/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Steffen
 */
@ManagedBean
@RequestScoped
@Entity
public class Forum implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable=false)
    private String theme;
    @OneToMany(cascade={CascadeType.ALL})
    private List<Reply> replies = new ArrayList<Reply>();
    
    public Forum(){
    }
    
    public Forum(String s){
        this.theme = s;
    }

    public void addReply(Reply reply){
        if(!reply.getMessage().equals("")) {
            replies.add(reply);
        }
    }
    
    
    /**
     * @return the theme
     */
    public String getTheme() {
        return theme;
    }

    /**
     * @param theme the theme to set
     */
    public void setTheme(String theme) {
        this.theme = theme;
    }

    /**
     * @return the replies
     */
    public List<Reply> getReplies() {
        return replies;
    }
    
    public int replyCount() {
        return replies.size();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
}
